package com.sgb.kjwl.view.ui.fragment.business;

import android.content.Context;
import androidx.databinding.DataBindingUtil;
import android.os.Bundle;
import androidx.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.sgb.kjwl.AppFragment;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.FragmentMemberInfoBinding;
import com.sgb.kjwl.di.self.DaggerSelfFragComponent;
import com.sgb.kjwl.di.self.SelfFragModule;
import com.sgb.kjwl.model.entity.business.MemberInfoEntity;
import com.sgb.kjwl.viewmodel.business.MemberInfoFragModel;
import com.swgk.core.base.di.AppComponent;

import javax.inject.Inject;

public class MemberInfoFragment extends AppFragment {
    public static final String TAG = "";
    private FragmentMemberInfoBinding binding;
    @Inject
    MemberInfoFragModel viewModel;
    private String id;


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }

    @Override
    public void onAttach(Context context) {
        super.onAttach(context);
    }

    @Override
    protected void setupFragmentComponent(AppComponent appComponent) {
        DaggerSelfFragComponent.builder()
                .appComponent(appComponent)
                .selfFragModule(new SelfFragModule(this))
                .build()
                .inject(this);
    }

    public static MemberInfoFragment newInstance(String id) {
        MemberInfoFragment fragment = new MemberInfoFragment();
        Bundle bundle = new Bundle();
        bundle.putString("id", id);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.fragment_member_info, container, false);
        return binding.getRoot();
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        initView();
        initData();
    }

    private void initView() {
        Bundle bundle =this.getArguments();//得到从Activity传来的数据
        if(bundle!=null){
            id = bundle.getString("id");
        }
    }

    public void initData() {
        viewModel.getMemberInfo(id);
    }

    public void showData(MemberInfoEntity memberInfoEntity){
        binding.tvAddress.setText(memberInfoEntity.getAddress());
        binding.tvAddWay.setText(memberInfoEntity.getAddType());
        binding.tvBankLevel.setText(memberInfoEntity.getBankLevel());
        binding.tvComName.setText(memberInfoEntity.getCompanyName());
        binding.tvComType.setText(memberInfoEntity.getCompanyType());
        binding.tvContact.setText(memberInfoEntity.getConcat());
        binding.tvCorn.setText(memberInfoEntity.getBankLoan());
        binding.tvFaren.setText(memberInfoEntity.getLegalPerson());
        binding.tvMakeBySelf.setText(memberInfoEntity.getProduct());
        binding.tvMemLevel.setText(memberInfoEntity.getMemberLevel());
        binding.tvMobile.setText(memberInfoEntity.getConcatNum());
        binding.tvPeopleNum.setText(memberInfoEntity.getEmployeeNum());
        binding.tvPrice.setText(memberInfoEntity.getTurnover());
        binding.tvGuding.setText(memberInfoEntity.getAssets());
        binding.tvTime.setText(memberInfoEntity.getAddTime());
    }
}
